package study.week03.gateway_final.netty;

import io.netty.channel.ChannelInitializer;
import io.netty.channel.ChannelPipeline;
import io.netty.channel.socket.SocketChannel;
import io.netty.handler.codec.http.HttpObjectAggregator;
import io.netty.handler.codec.http.HttpServerCodec;
import study.week03.gateway_final.filter.CustomHttpFilter;
import study.week03.gateway_final.inbound.InboundHandler;
import study.week03.gateway_final.router.CustomRouter;

import java.util.List;

public class HttpInitializer extends ChannelInitializer<SocketChannel> {
	private CustomHttpFilter[] filterChain ;
	private List<String> serverList;
	CustomRouter router;
	public HttpInitializer(CustomHttpFilter[] filterChain,  List<String> serverList, CustomRouter router) {
		this.filterChain = filterChain;
		this.serverList = serverList;
		this.router = router;
	}
	@Override
	public void initChannel(SocketChannel ch) {
		ChannelPipeline p = ch.pipeline();
		p.addLast(new HttpServerCodec());
		//p.addLast(new HttpServerExpectContinueHandler());
		p.addLast(new HttpObjectAggregator(1024 * 1024));
		p.addLast(new InboundHandler(filterChain,serverList,router));
	}
}